package org.hry.netty.demo;

import cn.hutool.json.JSONUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.util.List;

public class MyMessageDecoder extends MessageToMessageDecoder<String> {
    @Override
    protected void decode(ChannelHandlerContext ctx, String msg, List out) throws Exception {
        try {
            Message message = JSONUtil.toBean(msg, Message.class);
            out.add(message);
        } catch (Exception e) {
            out.add(msg);
        }
    }
}
